<!-- <div class="form-inline pull-right">
    <form action="#" method="get" pjax-container>
        <fieldset>
            <div class="btn-group btn-group-sm">
                <button type="submit" class="btn btn-primary">下单</button>
            </div>
        </fieldset>
    </form>
</div> -->

<!-- <link rel="stylesheet" href="1.css"> -->
<div class="btn-group" data-toggle="buttons">
    <!-- @foreach($options as $option => $label) -->
    <!-- <label  class="btn btn-default btn-sm {{ \Request::get('gender', 'all') == $option ? 'active' : '' }}"> -->
        <!-- {{$label}} -->
        <!-- <button id="demo_button" style="border:none; width:60px;height:30px;background:#3C8DBC; color:#FFFFFF">下单</button> -->
        <!-- <button id="demo_button" type="button" class="btn btn-default" data-toggle="modal" data-target="#demoModal" style="width:60px;height:32px;">下单</button> -->
      <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" style="width:60px;height:31px;" onclick="demo3()">下单</button>
<script type="text/javascript">
    function demo3(){
        $("#aa").css("display","block");
        $("#bb").css("display","none");
    }
</script>
    <!-- </label> -->
    <!-- @endforeach -->
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content" id="aa">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">客户搜索</h4>
                    <!-- <input type="text" class="clients_name-search_box fl qingchu" id="name" placeholder="请输入客户姓名"> -->
                    <input type="text" class="clients_name-search_box fl qingchu" id="phone" placeholder="请输入联系方式">

                    <input type="submit" value="搜索" class="clients_name-search-btn fl qingchu" onclick="demo()"><p id="tishi" style="color:red;display:none;">没有此客户信息请填写！</p><p id="tishi2" style="color:green;display:none;">此客户已存在，请核对信息！</p>
            </div>

            <!-- 有客户信息 -->
            <div class="modal-body" style="display:none;" id="one">
                <input type="hidden" id="customer_id" value="" name="customer_id">
                <div class="form-group">
                    <label for="firstname" class="col-sm-2 control-label">姓名</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="customer_name" id="customer_name">
                    </div>
                </div>

                <div class="form-group">
                    <label for="firstname" class="col-sm-2 control-label">性别</label>
                    <label class="radio-inline">
                        <input type="radio" name="customer_sex" class="sex qingchu" id="nan" value="1">  男
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="customer_sex" class="sex qingchu" id="nv" value="2"> 女
                    </label>
                </div>

                <div class="form-group">
                    <label for="firstname" class="col-sm-2 control-label">单位</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="customer_danwei" value="" name="customer_danwei">
                    </div>
                </div>

                <div class="form-group">
                    <label for="firstname" class="col-sm-2 control-label">电话</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="customer_phone" value="" name="customer_phone">
                    </div>
                </div>

                <div class="form-group">
                    <label for="firstname" class="col-sm-2 control-label">微信</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="customer_weixin" value="" name="customer_weixin">
                    </div>
                </div>

                <div class="form-group">
                    <label for="firstname" class="col-sm-2 control-label">Q Q</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="customer_qq" value="" name="customer_qq">
                    </div>
                </div>

                <div class="form-group">
                    <label for="firstname" class="col-sm-2 control-label">邮箱</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="customer_email" value="" name="customer_email">
                    </div>
                </div>

                <div class="form-group">
                    <label for="firstname" class="col-sm-2 control-label">身份证</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="customer_sfz" value="" name="customer_sfz">
                    </div>
                </div>
                
                <div class="form-group">
                    <label for="firstname" class="col-sm-2 control-label">来源</label>
                    <label class="radio-inline">
                        <input type="radio" name="customer_laiyuan" class="laiyuan qingchu" id="wangzhan" value="1"> 网站
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="customer_laiyuan" class="laiyuan qingchu" id="zhuanjieshao"  value="2"> 转介绍
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="customer_laiyuan" class="laiyuan qingchu" id="shangmen"  value="3"> 上门
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="customer_laiyuan" class="laiyuan qingchu" id="dianhua"  value="4"> 电话销售
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="customer_laiyuan" class="laiyuan qingchu" id="laokehu"  value="5"> 老客户
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="customer_laiyuan" class="laiyuan qingchu" id="qita"  value="6"> 其它
                    </label>
                </div>
            </div>
            
            <div class="modal-footer" id="three">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="demos()">保存并下单</button>

            </div>
        </div><!-- /.modal-content -->

        <!-- 工单 -->
        <div class="modal-content" id="bb" style="display:none">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">工单填写</h4>
            </div>
            <div class="modal-body" style="display: block;" id="one">
                <input id="order_customerid" value=" " name="order_customerid" type="hidden">
                <input id="order_route" value=" " type="hidden">

                <div class="form-group">

                    <label for="name">旅游意向地1</label>
                    <select class="form-control" name="order_didian" id="order_didian" style="width:150px;" onchange="show(this.options[this.options.selectedIndex].value)">
                      <!-- <option value="省内游">省内游</option>
                      <option value="国内游">国内游</option>
                      <option value="自由行">自由行</option>
                      <option value="签证">签证</option> -->
                    </select>
<script type="text/javascript">
    function show(v){
         // alert(v);
        $.ajax({
            url: "/admin/gdindex/ajax4",
            type: "post",
            dataType: "json",
            data: {'v': v,'_token': "{{csrf_token()}}"},
            success:function(data){
                for(var i=0;i<data.length;i++){
                    document.getElementById('order_didian2').options[i] = new Option(data[i].title,data[i].id);
                }
            }
        });                    
    }
</script>
                    <label for="name">旅游意向地2</label>
                    <select class="form-control" name="order_didian2" id="order_didian2" style="width:300px;">
                      <!-- <option value="省内游">省内游</option>
                      <option value="国内游">国内游</option>
                      <option value="自由行">自由行</option>
                      <option value="签证">签证</option> -->
                    </select>

                    <label for="name">旅游线路</label>
                    <!-- <select class="form-control" name="order_xianlu" id="order_xianlu"> -->
                    <input type="text" class="form-control" name="order_xianlu" id="order_xianlu">

                    </select>

                    <label for="name">标签</label>
                    <select class="form-control" name="order_lvyouleibie" id="order_lvyouleibie">
                      <option value="亲子游">亲子游</option>
                      <option value="夕阳红">夕阳红</option>
                      <option value="蜜月">蜜月</option>
                      <option value="其它">其它</option>
                    </select>

                    <label for="name">操作类别</label>
                    <select class="form-control" name="order_caozuoleibie" id="order_caozuoleibie">
                      <option value="自己">自己</option>
                      <option value="供应商">供应商</option>
                    </select>

                    <label for="name">旅游时间</label>
                    <input type="text" class="form-control" id="order_lvyoudate" value="" name="order_lvyoudate">

                    <!-- <label for="name">回访日期</label>
                    <input type="text" class="form-control" id="order_huifangdate" value="" name="order_huifangdate"> -->

                    <!-- <label for="name">工单状态</label>
                    <input type="text" class="form-control" name="order_statue" id="order_statue" value="商谈" readonly> -->

                    <!-- <select class="form-control" name="order_statue" id="order_statue">
                      <option>--请选择--</option>
                      <option value="成功">成功</option>
                      <option value="失败">失败</option>
                      <option value="商谈">商谈</option>
                      <option value="进行">进行</option>
                    </select> -->
                </div>
            </div>
            
            <div class="modal-footer" id="three">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="demo4()">提交</button>

            </div>
        </div>
    </div><!-- /.modal -->
</div>     
<script type="text/javascript">
                    function demo(){    
                    // alert($("#phone").val());            
                        $.ajax({
                            url: "/admin/gdindex/ajax",
                            type: "post",
                            dataType: "json",
                            data: {"phone": $("#phone").val(),'_token': "{{csrf_token()}}"},
                            success:function(data){
                                if(data == 2){
                                    $('#one').css("display","block");
                                    $("#tishi").css("display","block");
                                    $("#tishi2").css("display","none");
                                    // $("input:not(.qingchu)");
                                    $("input:not(.qingchu)").val("");
                                    // $("#one input").val(" ");
                                    // $('#nan').val('1');
                                    // $('#nan').val('2');
                                    // $("#one input[type='radio']").attr('checked', false);
                                }else{
                                    $('#one').css("display","block");
                                    $("#tishi").css("display","none");
                                    $("#tishi2").css("display","block");
                                    $("#customer_id").val(data.id);
                                    $("#customer_name").val(data.customer_name);
                                    if(data.customer_sex == 1){
                                         $('#nan').prop('checked', 'checked');
                                    }else if(data.customer_sex == 2){
                                         $('#nv').prop('checked', 'checked');
                                    }
                                    $("#customer_danwei").val(data.customer_danwei);
                                    $("#customer_phone").val(data.customer_phone);
                                    $("#customer_weixin").val(data.customer_weixin);
                                    $("#customer_qq").val(data.customer_qq);
                                    $("#customer_email").val(data.customer_email);
                                    $("#customer_sfz").val(data.customer_sfz);
                                    if(data.customer_laiyuan == 1){
                                         $('#wangzhan').prop('checked', true);
                                    }else if(data.customer_laiyuan == 2){
                                         $('#zhuanjieshao').prop('checked', true);
                                    }else if(data.customer_laiyuan == 3){
                                         $('#shangmen').prop('checked', true);
                                    }else if(data.customer_laiyuan == 4){
                                         $('#dianhua').prop('checked', true);
                                    }else if(data.customer_laiyuan == 5){
                                         $('#laokehu').prop('checked', true);
                                    }else if(data.customer_laiyuan == 6){
                                         $('#qita').prop('checked', true);
                                    }
                                    // $("#customer_beizhu").val(data.customer_beizhu);
                                };
                            }
                        });
                    };


                    function demos(){
                         // alert($(".sex:checked").val());
                        $.ajax({
                            url: "/admin/gdindex/ajax2",
                            type: "post",
                            dataType: "json",
                            data: {"id": $("#customer_id").val(),
                            "customer_name": $("#customer_name").val(),
                            "customer_sex":$(".sex:checked").val(),
                            "customer_danwei": $("#customer_danwei").val(),
                            "customer_phone": $("#customer_phone").val(),
                            "customer_weixin": $("#customer_weixin").val(),
                            "customer_qq": $("#customer_qq").val(),
                            "customer_email": $("#customer_email").val(),
                            "customer_sfz": $("#customer_sfz").val(),
                            "customer_laiyuan": $(".laiyuan:checked").val(),
                            '_token': "{{csrf_token()}}"},
                            success:function(data){
                                // alert(data);exit;
                                if(data!=1){
                                    alert("保存成功,点击填写工单");
                                    // alert(data.route.length);
                                    $("#aa").css("display","none");
                                    $("#bb").css("display","block");
                                    $("#order_customerid").val(data.id);
                                    $("#order_route").val(data.route);
                                    var j=0;
                                    for(var i=0;i<data.route.length;i++){
                                        // document.getElementById('order_didian').options[i] = new Option(data.route[i].route_name,data.route[i].route_name);
                                        if(data.route[i].parent_id == 0){
                                            document.getElementById('order_didian').options[i] = new Option(data.route[i].title,data.route[i].id);
                                        }
                                        // for(var j=0;j<data.route.length;j++){
                                            if(data.route[i].parent_id == data.route[0].id){
                                                document.getElementById('order_didian2').options[j] = new Option(data.route[i].title,data.route[i].id);
                                                j=j+1;
                                                // alert(j);
                                            }
                                            // alert(j);
                                        // }
                                    }
                                    // if($("#order_didian").val())
                                }else{
                                    alert("此电话号码已存在！");
                                }
                                
                            }
                        });
                    }

                    function demo4(){
                        // alert($("#order_customerid").val());
                        // alert($("#order_didian").val());
                        // alert($("#order_xianlu").val());
                        // alert($("#order_lvyouleibie").val());
                        // alert($("#order_caozuoleibie").val());
                        // alert($("#order_lvyoudate").val());
                        // alert($("#order_huifangdate").val());
                        // alert($("#order_statue").val());
                        $.ajax({
                            url: "/admin/gdindex/ajax3",
                            type: "post",
                            dataType: "json",
                            data: {"order_customerid": $("#order_customerid").val(),
                            "order_didian": $("#order_didian").val(),
                            "order_didian2": $("#order_didian2").val(),
                            "order_xianlu":$("#order_xianlu").val(),
                            "order_lvyouleibie": $("#order_lvyouleibie").val(),
                            "order_caozuoleibie": $("#order_caozuoleibie").val(),
                            "order_lvyoudate": $("#order_lvyoudate").val(),
                            "order_huifangdate": $("#order_huifangdate").val(),
                            "order_statue": $("#order_statue").val(),
                            '_token': "{{csrf_token()}}"},
                            success:function(data){
                                // alert(data);
                                if(data != 'cuowu'){
                                    alert('提交成功');
                                    // location.reload(true);
                                    window.location.reload();

                                }else{
                                    alert('提交失败');
                                    // location.reload(true);
                                }
                            }
                        });
                    }

</script>
        
